package com.lz.football.module.guide.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.ExploreEvent;
	import com.liangzhong.events.GuideEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.lz.football.module.explore.ExploreMapView;
	import com.lz.football.module.explore.ExploreView;
	import com.lz.football.module.guide.Guide;
	import com.lz.football.module.main.view.MainView;
	
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import lz.controls.managers.AnimationManager;

	/**
	 *球员探索引导 
	 * @author lake
	 * 
	 */	
	public class PlayerSearchGuideView extends Guide
	{
		public function PlayerSearchGuideView()
		{
			super();
		}
		/**
		 *初始化 
		 */		
		override protected function initView():void
		{
			super.initView();
			initDialog_1();
			//disable
			MainView.stadiumBtn.mouseEnabled = false;
			MainView.playerBtn.mouseEnabled = false;
		}
		/**
		 * 场景内对话框 
		 *	第二核心：球员！
			官方说法：球员是比赛取得好成绩的基础！
			1L：没有最好，只有更好？
			2L：来个巴乔先！
			3L：美工你好意思继续这样么~
		 * 
		 */		
		private function initDialog_1():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_5");
			GlobalDef.GameWindowContainer.addChild(bgMark);
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn1_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn1_Click(e :MouseEvent):void
		{
			removeBgMark();
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			TweenLite.delayedCall(.2,initDialog_2);
		}
		/**
		 * 场景内对话框 
		 *	球员探索
			官方说法：球员探索可以让玩家非常容易的探索到顶级球员！
			1L：球员探索，您值得拥有~
			2L：来个巴乔先！
			3L：-_-!
		 * 
		 */		
		private function initDialog_2():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_6");
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn2_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn2_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			TweenLite.delayedCall(.2,getFuncIcon);
		}
		/**
		 *获得按钮
		 */		
		private function getFuncIcon():void
		{
			GlobalDef.GameWindowContainer.addChild(bgMark);
			sceneBtn = Reflection.createInstance("com.football.main.playerSearchBtn");
			MainView.playerSearchBtn.visible = false;
			
			var appearMc :MovieClip = Reflection.createInstance("com.football.guide.AppearAtSkin");
			DisplayObjectUtil.removeAllChildren(appearMc.mc.mc);
			appearMc.mc.mc.addChild(sceneBtn);
			sceneBtn.x = -16;
			sceneBtn.y = -14;
			(sceneBtn as InteractiveObject).mouseEnabled = false;
			addDispToStage(appearMc);
			var entP :Point = MainView.playerSearchBtn.localToGlobal(new Point(0,0));
			AnimationManager.moveToThing(new Point(appearMc.x,appearMc.y),appearMc,entP,{delay:1,overwrite:0},.5);
			TweenLite.delayedCall(1.5,showFuncIcon);
		}
		/**
		 *显示按钮 
		 * 
		 */		
		private function showFuncIcon():void
		{
			MainView.playerSearchBtn.visible = true;
			removeBgMark();
			//限制区域
			var rectPoint :Point = MainView.playerSearchBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,MainView.playerSearchBtn.width,MainView.playerSearchBtn.height);
			step();
			//指向探索图标按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width/2,curClickRect.y);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,0);
			sceneBtn = MainView.playerSearchBtn;
			arrowAngle = 0;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
		}
		/**
		 *界面显示
		 * @param e
		 * 
		 */		
		private function onLoadResComplete2(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			GlobalDef.GameContainer.addChild(bgMark);
			//限制区域
			var rectPoint :Point = ExploreMapView._skin.asiaBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y+50,ExploreMapView.asiaBtn.width,ExploreMapView.asiaBtn.height-50);
			step();
			//指向亚洲
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/5);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn = ExploreMapView._skin.asiaBtn;
			arrowAngle = -90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(ExploreEvent.EXPLORE_PLAYER,onExplorePlayer);
		}
		/**
		 * 探索球员 
		 * @param e
		 * 
		 */		
		private function onExplorePlayer(e :Event):void
		{
			//提交引导
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE,{step:3}));
			removeArrowMc();
			GlobalDef.GameWindowContainer.addChild(bgMark);
			AppEventDispatcher.getInstance().removeEventListener(ExploreEvent.EXPLORE_PLAYER,onExplorePlayer);
			//TweenLite.delayedCall(8,ptSignBtn);
			AppEventDispatcher.getInstance().addEventListener("Guide_explore_PlayerMc_AP",ptSignBtn);
		}
		/**
		 *指向签约 
		 */		
		private function ptSignBtn(e :Event = null):void
		{
			AppEventDispatcher.getInstance().removeEventListener("Guide_explore_PlayerMc_AP",ptSignBtn);
			removeBgMark();
			//限制区域
			var rectPoint :Point = ExploreView.signBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,ExploreView.signBtn.width,ExploreView.signBtn.height);
			step();
			//指向签约
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn = ExploreView.signBtn;
			arrowAngle = 90;
			//事件
			AppEventDispatcher.getInstance().addEventListener("player_searchAlert",alertShowHandler);
		}
		/**
		 * 提示框 
		 * @param e
		 * 
		 */		
		private function alertShowHandler(e :NotifierEvent):void
		{
			AppEventDispatcher.getInstance().removeEventListener("player_searchAlert",alertShowHandler);
			removeArrowMc();
			var alDisp :* = e.params;
			var yesBtn :DisplayObject = alDisp["_Yes"];
			if(yesBtn)
			{
				//限制区域
				var rectPoint :Point = yesBtn.localToGlobal(new Point(0,0));
				curClickRect = new Rectangle(rectPoint.x,rectPoint.y,yesBtn.width,yesBtn.height);
				step();
				//指向确认
				var arrrowPoint :Point = new Point(curClickRect.x - 10,curClickRect.y + curClickRect.height/2);
				addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
				sceneBtn = yesBtn;
				arrowAngle = -90;
			}
			//事件
			GlobalDef.GameStage.addEventListener(ExploreEvent.SIGN,onSignHandler);
		}
		/**
		 *签约 
		 * @param e
		 * 
		 */		
		private function onSignHandler(e :Event):void
		{
			GlobalDef.GameStage.removeEventListener(ExploreEvent.SIGN,onSignHandler);
			//限制区域
			var rectPoint :Point = ExploreView.closeBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,ExploreView.closeBtn.width,ExploreView.closeBtn.height);
			step();
			//指向关闭按钮
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width + 10,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,90);
			sceneBtn = ExploreView.closeBtn;
			arrowAngle = 90;
			//事件
			GlobalDef.GameStage.addEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
		}
		/**
		 *  关闭
		 * @param e
		 * 
		 */		
		private function onRemoveModuleHandler(e :Event):void
		{
			GlobalDef.GameStage.removeEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
			removeArrowMc();
			//@lake 2013-11-15
			//第3步刷新
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE+"_refresh",{step:3}));
			//enable
			MainView.stadiumBtn.mouseEnabled = true;
			MainView.playerBtn.mouseEnabled = true;
		}
		/**
		 *执行 
		 * 
		 */		
		override public function process():void
		{
			initView();
		}
		/**
		 *清理 
		 * 
		 */		
		override public function clear():void
		{
			if(dialogBtn)
			{
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_Click);
			}
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete2);
			AppEventDispatcher.getInstance().removeEventListener(ExploreEvent.EXPLORE_PLAYER,onExplorePlayer);
			AppEventDispatcher.getInstance().removeEventListener("Guide_explore_PlayerMc_AP",ptSignBtn);
			AppEventDispatcher.getInstance().removeEventListener("player_searchAlert",alertShowHandler);
			GlobalDef.GameStage.removeEventListener(ExploreEvent.SIGN,onSignHandler);
			GlobalDef.GameStage.removeEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModuleHandler);
			super.clear();
		}
	}
}